﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace COFE.Core.Utils
{
    public static class TestUtils
    {
        public static string Indent(int count)
        {
            StringBuilder sb = new StringBuilder();
            for (var i = 0; i < count; i++)
                sb.Append(" ");
            return sb.ToString();
        }

        public static TimeSpan Benchmark(int indent, string name, Action action)
        {            
            if (indent == 0)
                Console.WriteLine(Indent(indent) + name);
            else Console.Write(Indent(indent) + name + " - ");

            DateTime startTime = DateTime.UtcNow;
            action.Invoke();
            DateTime endTime = DateTime.UtcNow;
            TimeSpan timeUsed = endTime.Subtract(startTime);
            if (indent == 0)
                Console.WriteLine(Indent(indent) + "Total time spent - " + timeUsed.TotalSeconds.ToString() + "s");
            else Console.WriteLine(timeUsed.TotalSeconds.ToString() + "s");
            return timeUsed;

        }
    }
}
